<%@language=VBScript%>
<%
	Session("bChucnang")=4
	Session("FormName")="F19"
%>
<!--#include file="..\RootContent.inc"-->
<!--#include file=..\getFormName.inc-->
<script language=vbscript runat=server>
Sub DeleteMessage(MsgNo,strHost, strUid, strPwd)
    Set Mailer = Server.CreateObject("POP3svg.Mailer")
    Mailer.RemoteHost = strHost
    Mailer.UserName   = strUid
    Mailer.Password   = strPwd
    Mailer.OpenPop3
    Mailer.Delete MsgNo
    Mailer.ClosePop3
End sub
function Attachfile(MsgNo,bMaID,bYear,bHost,bUid,bPwd)
    Set Mailer = Server.CreateObject("POP3svg.Mailer")
    strMailBaseDir =server.MapPath("..\Xuly\temp")
    Mailer.MailDirectory = strMailBaseDir
    Mailer.RemoteHost =bHost 'Session("HostMail")
    Mailer.UserName   =bUid 'Session("UidMail")
    Mailer.Password   = bPwd 'Session("PwdMail")
    Mailer.OpenPop3
    Mailer.Pop3Log = "c:\pop3log.txt"
    Mailer.Retrieve MsgNo    
    set Obj=server.CreateObject("ActiveFile.File")
	Set TextFile=server.CreateObject("Vinalines.ClsFile")
	Tentep=RootContent & "upload\"& byear &"\Den\text\"& bMaID &  ".VT"
	TextFile.SaveFile Request("TxtBody"),Tentep
	if Mailer.AttachmentCount > 0 then
      For intCount = 1 to Mailer.AttachmentCount      
        if Mailer.GetAttachmentInfo (intCount) then
          Mailer.SaveAttachment (intCount)
		STT=1				
		Tentep=bMaID & "S" & cstr(intCount) & "."&  TextFile.GetExtensionFile(Mailer.AttFileName)
		P1=strMailBaseDir  & "\" & Mailer.AttFileName
		Obj.Name=P1	
		if Obj.Exists() then
			P2= RootContent & "upload\"& byear &"\Den\"& Tentep
			Obj.Copy(P2)
			Mailer.EraseFile p1
		end if
		sSQL="Insert into vanban_Noidung(Mavanthu,Loaivanthu,SoThutu,tentep,mota) values('"& bMaID &"','1',"& cstr(STT) &",'"& tentep &"','"& Mailer.AttFileName &"')"
		Conn.Execute sSQL							
        end if
      Next    	
	end if
	Mailer.ClosePop3
	set Obj=nothing
	set TextFile=nothing
	set mailer=nothing												
end function
Function LayIDDT(bStr )
    bStr = Trim(bStr)
    Dim bSo 
    bSo = InStr(1, bStr, "_ID", vbTextCompare)
    If bSo Then
        LayIDDT = Mid(bStr, bSo + 3)
    End If
End Function
</script>
<SCRIPT ID=clientEventHandlersVB LANGUAGE=VBscript>
<!--
function TxtSearchDT_onchange() 
	for each pt in Noidung.ComboDoitac
		if instr(1,pt.value,Noidung.TxtSearchDT.value,vbTextCompare) then
			Noidung.ComboDoitac.value=pt.value
			exit for
		end if
	next
end function
//-->
</SCRIPT>

<!--#include file="..\CheckSession.inc"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
</head>
<%	
	Dim Msg,bPhanloai	
	bComm=Request("bComm")	
	if bComm="edit" then
		bSogoccu=Request("TxtSogoc")
		bIDcu=Request("TxtID")
		sSQL="Select * from VTDen Where ID Like '"& bIDcu &"'"
		Set RecT=Server.CreateObject("ADODB.Recordset")
		RecT.CursorType=3
		RecT.CacheSize=5
		RecT.Open sSQL,Conn
		Dim bDisplay
		bDisplay=False
		if RecT.RecordCount>0 then
			dim bSoghinhan
			Dim bSogoccu
			Dim bID
			Session("bMaVB")=RecT("ID")				
			Session("bTenVB")=RecT("Trichyeu")		
			bSoghinhan=RecT("soghinhan")		
			bSoghinhancu=RecT("soghinhan")			
			bSogoc=RecT("Sogoc")
			bSogoccu=RecT("Sogoc")
			bIDcu=RecT("ID")
			bID=RecT("ID")
			bNam=year(RecT("Ngaynhan"))		
			bNamcu=year(RecT("Ngaynhan"))
			bTrichyeu=RecT("Trichyeu")
			bTinhchat=RecT("Tinhchat")
'			bTinhchat1=RecT("Tinhchat1")
			bPhanloai=RecT("phanloai")
			bDoitac=RecT("Doitac")
			bNgaynhan=RecT("Ngaynhan")
			bTentep=RecT("Tentep")
			bTentepcu=RecT("Tentep")
			bNguoiky=RecT("Nguoiky")
			bNgayky=RecT("Ngayky")
			bNoinhan=RecT("Noinhan")
			bNguoinhan=RecT("Nguoinhan")
			'bVuviec=RecT("Vuviec")
			bTukhoa=RecT("Tukhoa")
			bNoigui=RecT("noigui")
			bReadwrite=RecT("congcong")
			bCongcong=RecT("congcong")
			bTTDuyet=RecT("trangthaiduyet")
			bDiachiluutru=RecT("diachiluutru")
			bSLNoidung=RecT("Soluongnoidung")
			bBaocao=RecT("Baocao")
			bTomtat=RecT("tomtat")
			bDisplay=true
		else
			'Response.Redirect("frmdsvtden.asp?Chuachon=thongtin")
		end if
	end if
	Dim bTonTai
	Select case bComm
		case "okedit"		
			bSoghinhan=Request("TxtSoghinhan")
			bSogoc=Request("TxtSogoc")
			bNam=year(Request("Txtngaynhan"))
			bTrichyeu=trim(Request("TxtTrichyeu"))
			bTinhchat=Request("ComboTinhchat")
			'bTinhchat1=Request("ComboTinhchat1")
			bPhanloai=Request("ComboPhanloai")
			bDoitac=Request("ComboDoitac")
			bDoitac=bDoitac
			bPhanloai=Request("ComboPhanloai")
			bNgaynhan=Request("TxtNgaynhan")
			bTentep=Request("TxtTentep")
			bNguoiky=trim(Request("TxtNguoiky"))
			bNGayky=request("TxtNgayky")
			bNoinhan=trim(request("TxtNoinhan"))
			bNguoinhan=Request("TxtNguoinhan")
			bTukhoa=Request("TxtTukhoa")
			bReadwrite=Request("bReadwrite")
			bTomtat=trim(Request("TxtTomtat"))
			if bReadwrite then
				bReadwrite=1
			else
				bReadwrite=0
			end if
			bBaocao=Request("ChkBC")
			if bBaocao then
				bBaocao=1
			else
				bBaocao=0
			end if
			bCongcong=Request("congcong")
			if bCongcong then
				bCongcong=1
			else
				bcongcong=0
			end if
			bNoigui=trim(Request("TxtNoigui"))
			bSoghinhancu=Request("bSoghinhancu")
			bIDcu=Request("bIDcu")
'			bDiachiluuTru=Request("Txtdiachiluutru")
			bDiachiluutru=0
			bNamcu=Request("bNamcu")
			bTTDuyet=Request("bTTDuyet")
			if bTTDuyet then
				bTTDuyet=1
			else
				bTTDuyet=0
			end if
			bSLNoidung=Request("TxtSLNoidung")
			if Request("filename")<>"" then
				bTentepcu=Request("filename")
			end if
			Temp=bSoghinhan
			bID="DE"+cstr(bNam)+"_"+Doima(Temp)
			bTentep=bID+".VT"						
			bNguoiduyet=Session("bMaCB")
			bNgaynhan=SaveDate(bNgaynhan)
			bNgayky=SaveDate(bNgayky)
			On Error resume next
			Conn.BeginTrans
			bUpdate=false
			if (trim(bSoghinhancu)=trim(bSoghinhan)) and (cstr(bNam)=cstr(bNamcu)) then
				sSQL="Update VTDen set Sogoc='"& ModiString(bSogoc) _
					&"',ngayky='"& bNgayky _
					&"',Nguoiky='"& ModiString(bNguoiky) _
					&"',Trichyeu='"& ModiString(bTrichyeu) _
					&"',Tomtat='"& ModiString(bTomtat) _
					&"',Tukhoa='"& ModiString(bTukhoa) _
					&"',Ngaynhan='"& bNgaynhan _
					&"',Nguoinhan='"& ModiString(bNguoinhan) _
					&"',Tinhchat='"& ModiString(bTinhchat) _
					&"',Phanloai='"& bPhanloai _
					&"',Doitac='"& ModiString(bDoitac) _
					&"',Noinhan='"& ModiString(bNoinhan) _
					&"',Noigui=' ',Tentep='"& ModiString(bTentep) _
					&"',diachiluutru="& bDiachiluutru _
					&",Congcong="& bReadwrite _
					&",trangthaiduyet="& bTTDuyet _
					&",Nguoiduyet='"& bNguoiduyet _
					&"',Baocao="& bBaocao _
					&" Where ID ='"& bIDcu &"'" 
				Conn.Execute sSQL				
			end if
			
			if (bSoghinhancu<>bSoghinhan) and (cstr(bNam)=cstr(bNamcu)) then
				Temp=bSoghinhan
				bID="DE"+cstr(bNam)+"_"+Doima(Temp)
				if KTSoghinhan(bSoghinhan,bNam,"okedit") then
					Msg="M&#227; s&#7889; ghi nh&#7853;n &#273;&#227; t&#7891;n t&#7841;i"
					bTontai=True
					bDisplay=true
					bComm="edit"
					bSoghinhancu=request("bSoghinhancu")
					bSogoccu=Request("bSogoccu")
					bIDcu=Request("bIDcu")
					bNamcu=	Request("bNamcu")
					bID=bIDCu
					bSoghinhan=bSoghinhancu
				else
					Msg="N&#7897;i dung &#273;&#227; &#273;&#432;&#7907;c s&#7917;a"
					bTonTai=false
					bComm="edit"												
				end if
				if not bTonTai then
					sSQL="Update VTDen set ID='"& ModiString(bID) _
					&"',Soghinhan='"& ModiString(bSoghinhan) _
					&"',Sogoc='"& ModiString(bSogoc) _
					&"',ngayky='"& bNgayky _
					&"',Nguoiky='"& ModiString(bNguoiky) _
					&"',Trichyeu='"& ModiString(bTrichyeu) _
					&"',Tomtat='"& ModiString(bTomtat) _
					&"',Tukhoa='"& ModiString(bTukhoa) _
					&"',Ngaynhan='"& bNgaynhan _
					&"',Nguoinhan='"& ModiString(bNguoinhan) _
					&"',Tinhchat='"& ModiString(bTinhchat) _
					&"',Phanloai='"& bPhanloai _
					&"',Doitac='"& bDoitac &"',Noinhan='"& ModiString(bNoinhan) _
					&"',Noigui=' ',Tentep='"& ModiString(bTentep) _
					&"',diachiluutru="& bDiachiluutru _
					&",Congcong="& bReadwrite _
					&",trangthaiduyet="& bTTDuyet _
					&",Nguoiduyet='"& bNguoiduyet _
					&"',Baocao="& bBaocao _
					&" Where ID ='"& bIDcu &"'" 					
					Conn.Execute sSQL				
					bUpdate=true
				end if
			end if
			if (cstr(bNam)<>cstr(bNamcu)) then				
				if KTSoghinhan(bSoghinhan,bNam,"okedit") then																
					sSQL="Select * from vtden where year(ngaynhan)="& bNam &"  order by len(soghinhan),soghinhan"					
					Set RecTD=server.createobject("ADODB.Recordset")
					RecTD.cursorType=3
					RecTD.Cachesize=5
					RecTD.open sSQL,Conn					
					if (not RecTD.EOF) and (not RecTD.BOF) then
						RecTD.MOvelast
						bSoghinhan=cstr(clng(RecTD("Soghinhan"))+1)												
					else
						bSoghinhan="1"
					end if
					RecTD.close
					Set RecTD=nothing
				end if				
				Temp=bSoghinhan
				bID="DE"+cstr(bNam)+"_"+Doima(Temp)
				sSQL="Update VTDen set ID='"& ModiString(bID) _
					&"',Soghinhan='"& ModiString(bSoghinhan) _
					&"',Sogoc='"& ModiString(bSogoc) _
					&"',ngayky='"& bNgayky _
					&"',Nguoiky='"& ModiString(bNguoiky) _
					&"',Trichyeu='"& ModiString(bTrichyeu) _
					&"',Tomtat='"& ModiString(bTomtat) _
					&"',Tukhoa='"& ModiString(bTukhoa) _
					&"',Ngaynhan='"& bNgaynhan _
					&"',Nguoinhan='"& ModiString(bNguoinhan) _
					&"',Tinhchat='"& ModiString(bTinhchat) _
					&"',Phanloai='"& bPhanloai _
					&"',Doitac='"& bDoitac &"',Noinhan='"& ModiString(bNoinhan) _
					&"',Noigui=' ',Tentep='"& ModiString(bTentep) _
					&"',diachiluutru="& bDiachiluutru _
					&",Congcong="& bReadwrite _
					&",trangthaiduyet="& bTTDuyet _
					&",Nguoiduyet='"& bNguoiduyet _
					&"',Baocao="& bBaocao _
					&" Where ID ='"& bIDcu &"'" 
					Conn.Execute sSQL
					bUpdate=true
			end if
			%><%=Err.Description%><%
			if bUpdate then
				sSQL="Update Muontra set BophanQL="& bDiachiluutru &",matailieu = '"& ModiString(bID) &"' where matailieu like '"& bIDcu &"' and Loaitailieu=1"
				Conn.Execute sSQL 
				sSQL="Update vanban_noidung set mavanthu='"& ModiString(bID) &"' where mavanthu Like '"& bIDcu &"' and loaivanthu='1'" 				
				Conn.Execute sSQL
				'Sua File
				set TextFile=server.CreateObject("Activefile.file")
				PathOld=RootContent & "Upload\"& cstr(bNamcu) &"\Den\Text"
				PathOld=Pathold & "\" & bIDcu & ".VT" 
				Path=RootContent & "Upload\"& cstr(bNam) &"\Den\Text"
				Path=Path & "\" & bID & ".VT" 	
				
				'Tao thu muc nam moi
				Set bDir=server.CreateObject("ActiveFile.Directory")
			     bPathFolder=RootContent & "Upload\" & bNam
		          bDir.Path=bPathFolder
       			if not bDir.Exists() then
       			   	call bDir.Create(bPathFolder)
       			end if
       			bPathFolder=bPathFolder & "\Den"
				bDir.Path=bPathFolder
		     	if not bDir.Exists() then
					Call bDir.Create(bPathFolder)
				end if
	    			bPathFolder=bPathFolder & "\Text"
			    	bDir.Path=bPathFolder
	    			if not bDir.Exists() then
		    			Call bDir.Create(bPathFolder)
				end if
		          Set bDir=nothing		          
		          TextFile.Name=Path		          
				if TextFile.Exists() then
					TextFile.Delete()
				end if				
				TextFile.Name=PathOld	
				if TextFile.Exists() then
					Call TextFile.Copy (Path)				
				end if
				TextFile.Name=PathOld				
				if TextFile.Exists() then
					TextFile.Delete()
				end if				
				sSQL="Select * from vanban_noidung where mavanthu Like '"& ModiString(bID) &"' and Loaivanthu='1'  order by Sothutu"
				Set RecRename=server.CreateObject("ADODB.Recordset")
				RecRename.CursorType=3
				RecRename.CacheSize=5
				RecRename.Open sSQL,Conn
				Set Ex=server.CreateObject("Vinalines.ClsFile")				
				Do while not RecRename.EOF					
					Pathold=RootContent & "Upload\"& Cstr(bNamcu) &"\Den"
					Pathold=Pathold & "\" & bIDcu & "S" & trim(cstr(RecRename("sothutu"))) & "." & Ex.GetExtensionFile(RecRename("Tentep"))			
					Path=RootContent & "Upload\"& Cstr(bNam) &"\Den"
					Path=Path & "\" & bID & "S" & trim(cstr(RecRename("sothutu"))) & "." & Ex.GetExtensionFile(RecRename("Tentep"))			
					TextFile.Name=Path
					if TextFile.Exists() then
						TextFile.delete()
					end if
					TextFile.Name=PathOld
					if TextFile.Exists() then
						call TextFile.Copy (Path)
						TextFile.Delete()
					end if
					bName=bID & "S" & trim(cstr(RecRename("sothutu"))) & "." & Ex.GetExtensionFile(RecRename("Tentep"))
					sSQL="Update vanban_noidung set Tentep='"& bName &"' where loaivanthu='1' and   Sothutu="& RecRename("sothutu") &" And mavanthu like '"& ModiString(bID) &"'"
					Conn.Execute sSQL
					RecRename.MoveNext
				Loop
				RecRename.Close
				set RecRename=nothing
				set TextFile=nothing
				Set Ex=nothing
				if bReadwrite then
					sSQL="Delete Quyen where maloaivanthu='1' and mavanthu like '"& ModiString(bID) &"'"
					Conn.Execute sSQL
				end if
				sSQL="Update vanban_vuviec set mavanban='"& ModiString(bID) &"' where mavanban Like '"& bIDcu &"' and loaivanban='1'" 
				Conn.Execute sSQL								
			end if
			bSoghinhancu=bSoghinhan
			bIDcu=bID
			bNamcu=bNam
			bSogoccu=bSogoc
			Session("bMaVB")=bID
			Session("bTenVB")=bTrichyeu
			'Ket Thuc Trasaction

			if Err.number=0 then
				Conn.CommitTrans
				bTrangthai=1
			else
				Conn.RollbackTrans
				bTrangthai=0
			end if
			'Ghi nhan Ai da login thanh cong				
			bHoten=Session("bHoten")
			bNgaygio=cstr(Date()) &" "& cstr(Time())
			bChucnang="C&#7853;p nh&#7853;t V&#259;n th&#432; &#273;&#7871;n"
			bIDTailieu=bSoghinhan
			bDongtac="S&#7917;a"
			sSQL="insert into loguser(Tennguoisudung,ngaygio,chucnangdung,dongtac,IDTailieu,Trangthai) Values('"& bHoten _
				&"','"& bNgaygio &"','"& bChucnang &"','"& bDongtac &"','"& bIDTailieu &"',"& bTrangthai &")"
			Conn.Execute sSQL		
			bComm="edit"				
		case "okadd"			
			bNam=year(Request("TxtNgaynhan"))			
			bSogoc=Request("TxtSogoc")
			bTrichyeu=trim(Request("TxtTrichyeu"))
			bTinhchat=Request("ComboTinhchat")
			bTinhchat1=Request("ComboTinhchat1")
			bPhanloai=Request("ComboPhanloai")
			bDoitac=Request("Combodoitac")
			bDoitac=bDoitac
			bNgaynhan=Request("TxtNgaynhan")
			bTentep=Request("TxtTentep")
			bNguoiky=trim(Request("TxtNguoiky"))
			bNGayky=request("TxtNgayky")
			bNoinhan=trim(request("TxtNoinhan"))
			bNguoinhan=Request("TxtNguoinhan")
			bTukhoa=Request("TxtTukhoa")
			bReadwrite=Request("bReadwrite")
			bTomtat=trim(Request("TxtTomtat"))
			if bReadwrite then
				bReadwrite=1
			else
				bReadwrite=0
			end if
			bBaocao=Request("ChkBC")
			if bBaocao then
				bBaocao=1
			else
				bBaocao=0
			end if
			bCongcong=Request("congcong")
			if bCongcong then
				bCongcong=1
			else
				bCongcong=0
			end if
'			bDiachiluutru=request("Txtdiachiluutru")
			bDiachiluutru=0
			bTTDuyet=Request("bTTDuyet")
			if bTTDuyet then
				bTTDuyet=1
			else
				bTTDuyet=0
			end if
			bNoigui=trim(Request("TxtNoigui"))
			bSLNoidung=Request("TxtSLNoidung")	
			bSoghinhan=Request("TxtSoghinhan")
			
			if KTSoghinhan(bSoghinhan,bNam,"okadd") then
				Set RecMax=server.createObject("ADODB.Recordset")
				RecMax.cursortype=3
				RecMax.cachesize=5
				sSQL="Select * from vtden where year(ngaynhan)="& bNam &" order by len(soghinhan),soghinhan"
				RecMax.open sSQL,Conn
				if RecMax.recordcount then
					RecMax.movelast
					bSoghinhan=cstr(cint(RecMax("soghinhan"))+1)
				else
					bSoghinhan="1"
				end if
				RecMax.close
				Set RecMax=nothing
			end if
			Temp=bSoghinhan
			bID="DE"+cstr(bNam)+"_"+Doima(Temp)
			Msg="N&#7897;i dung c&#7853;p nh&#7853;t"
			bTonTai=false
			bComm="edit"
			bSoghinhancu=bSoghinhan
			bSogoccu=bSogoc
			bIDcu=bID
			bNamcu=bNam
		
			if not bTonTai then
				' Tao Transaction					
				On Error resume next
				Conn.BeginTrans
				
				bTentep=bID+".VT"
				bNguoiduyet=Session("bMaCB")
				bNgaynhan=SaveDate(bNgaynhan)
				bNgayky=SaveDate(bNgayky)
				sSQL="Insert Into VTDen(ID,soghinhan,sogoc,trichyeu,tinhchat,tinhchat1,ngaynhan,phanloai,doitac,tentep,nguoiky,ngayky,diachiluutru,noinhan,nguoinhan,tukhoa,congcong,noigui,trangthaiduyet,nguoiduyet,Soluongnoidung,baocao,tomtat) values('"& modistring(bID) &"','"& modistring(bSoghinhan) _
						&"','"& ModiString(bSogoc) &"','"& ModiString(bTrichyeu) _
						&"','"& ModiString(bTinhchat) &"','"& ModiString(bTinhchat1) &"','"& bNgaynhan _
						&"','"& ModiString(bPhanloai) _
						&"','"& ModiString(bDoitac) &"','"& ModiString(bTentep) &"','"& ModiString(bNguoiky) _
						&"','"& bNgayky &"',"& ModiString(bDiachiluutru) &",'"& ModiString(bNoinhan) _
						&"','"& ModiString(bNguoinhan) _
						&"','"& ModiString(bTukhoa) &"',"& ModiString(bReadwrite) _
						&",' ',"& bTTDuyet &",'"& bNguoiduyet &"','"& bSLNoidung &"',"& bBaocao &",'"& ModiString(bTomtat) &"')"					
				Conn.Execute sSQL
				%><%=Err.Description%><%
				'Attach file
				MsgNo=Request("MsgNo")
				if MsgNo then
					if Request("bSendFrom")="mail" then
						call Attachfile(MsgNo,bID,bnam,Session("HostMail"),Session("UidMail"),Session("PwdMail"))
						call DeleteMessage(MsgNo,Session("HostMail"),Session("UidMail"),Session("PwdMail"))
					end if
					if Request("bSendFrom")="fax" then
						call Attachfile(MsgNo,bID,bnam,Session("HostFax"),Session("UidFax"),Session("PwdFax"))
						call DeleteMessage(MsgNo,Session("HostFax"),Session("UidFax"),Session("PwdFax"))
					end if
				end if

				'Ket Thuc Trasaction
				if Err.number=0 then
					if Session("VanBan")="" then 
						Session("VanBan")="-" & Session("VanBan") & modistring(bID) & "-"
					else
						Session("VanBan")=Session("VanBan") & modistring(bID) & "-"
					end if
					Session("sSQLDen")=""
					Conn.CommitTrans
					bTrangthai=1
				else
					Conn.RollbackTrans
					bTrangthai=0
				end if		
								
				'Ghi nhan Ai da login thanh cong				
				bHoten=Session("bHoten")
				bNgaygio=cstr(Date()) &" "& cstr(Time())
				bChucnang="C&#7853;p nh&#7853;t V&#259;n th&#432; &#273;&#7871;n"
				bIDTailieu=bSoghinhan
				bDongtac="Th&#234;m m&#7899;i"
				sSQL="insert into loguser(Tennguoisudung,ngaygio,chucnangdung,dongtac,IDTailieu,Trangthai) Values('"& bHoten _
					&"','"& bNgaygio &"','"& bChucnang &"','"& bDongtac &"','"& bIDTailieu &"',"& bTrangthai &")"
				Conn.Execute sSQL
				
				Session("bMaVB")=bID
				Session("bTenVB")=bTrichyeu
			end if
	end select	
	if bComm=""  then
		bVuviec=false
	else
		bVuviec=true
	end if
	'Kiem tra(Lay quyen va ma van thu) quyen doi voi van thu
	if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),4)="1" or Session("IsAdmin") then
		bQuyen="F"
	else
		sSQL="Select * from Quyen Where Mavanthu like '"& bID &"' and Macanbo like '"& Session("bMaCB") &"' and maloaivanthu like '1'"
		Set RecKTQ=server.CreateObject("ADODB.Recordset")
		RecKTQ.CursorType=3
		RecKTQ.CacheSize=5
		RecKTQ.Open sSQL,Conn
		if RecKTQ.RecordCount>0 then
			bQuyen=RecKTQ("Quyen")
		end if
		RecKTQ.Close
		set RecKTQ=nothing
	end if
%>
<!--#include file="..\jvfunction.inc"-->
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function KTNhap(){
	if (Noidung.TxtNgaynhan.value==""){
		alert("Cho biết ngày đến");
		Noidung.TxtNgaynhan.focus();
		return false;
	}

	if (trim(Noidung.TxtSoghinhan.value)==""){
		alert("Bạn cần phải nhập số ghi nhận");
		Noidung.TxtSoghinhan.focus();
		return false;
	}
	if(daucach(Noidung.TxtSoghinhan.value)){
		alert("Mã không được chứa các ký tự đặc biệt(',space)");
		Noidung.TxtSoghinhan.focus();
		return false;
	}
	if (Noidung.TxtSogoc.value==""){
		alert("Bạn cần phải nhập số, ký hiệu công văn");
		Noidung.TxtSogoc.focus();
		return false;
	}
	if(daucach(Noidung.TxtSogoc.value)){
		alert("Mã không được chứa các ký tự đặc biệt(',space)");
		Noidung.TxtSogoc.focus();
		return false;
	}
	if (Noidung.TxtTrichyeu.value==""){
		alert("Cho biết trích yếu");
		Noidung.TxtTrichyeu.focus();
		return false;
	}
	if (Noidung.ComboDoitac.value==""){
		alert("Cho biết cơ quan ban hành");
		Noidung.ComboDoitac.focus();
		return false;
	}
	if (Noidung.TxtNgayky.value==""){
		alert("Cho biết ngày công văn");
		Noidung.TxtNgayky.focus();
		return false;
	}
	if (Noidung.ComboTinhchat.value==""){
		alert("Cho biết độ khẩn");
		Noidung.ComboTinhchat.focus();
		return false;
	}
	if (Noidung.ComboPhanloai.value==""){
		alert("Cho biết tên loại văn bản");
		Noidung.ComboPhanloai.focus();
		return false;
	}
	return true;
}

function CmdExit_onclick() {
	window.Noidung.target="right"
	window.Noidung.action="frmdsvtden.asp?bComm=";
	window.Noidung.submit();
}

function window_onload() {

}
function CmdOK_onclick() {
	if (KTNhap()){	
		if(Noidung.TxtNgayky.value!=""){	
			if (!isDate(Noidung.TxtNgayky.value)){
				alert("Ngày ký không hợp lệ");
				Noidung.TxtNgayky.focus();
				return false;
			}
		}	
		if(Noidung.TxtNgaynhan.value!=""){
			if (!isDate(Noidung.TxtNgaynhan.value)){
				alert("Ngày nhận không hợp lệ");
				Noidung.TxtNgaynhan.focus();
				return false;
			}
		}

		<%if bComm="edit" then%>
			window.Noidung.target="right"
			//window.Noidung.action="frmVTDen.asp?bComm=okedit&bIDcu="+"<%=bIDcu%>"+"&filename="+Noidung.TxtTenTep.value+"&bSogoccu="+"<%=bSogoccu%>"+"&bReadwrite="+Noidung.CheckReadwrite.checked+"&bTTDuyet="+"<%=bTTDuyet%>"
			window.Noidung.action="frmVTDen.asp?bSoghinhancu="+"<%=bSoghinhancu%>"+"&bComm=okedit&bIDcu="+"<%=bIDcu%>"+"&bNamcu="+"<%=bNamcu%>"+"&bSogoccu="+"<%=bSogoccu%>"+"&bReadwrite="+Noidung.CheckReadwrite.checked+"&bTTDuyet="+"<%=bTTDuyet%>"						
			window.Noidung.submit()
		<%end if%>
		<%if bComm="add" then%>
			window.Noidung.target="right"
			<%MsgNo=Request("MsgNo")
			bSendfrom=Request("bSendfrom")
			if MsgNo then%>
			window.Noidung.action="frmVTDen.asp?bSendfrom="+"<%=bSendfrom%>"+"&MsgNo="+<%=MsgNo%>+"&bSoghinhancu="+"<%=bSoghinhancu%>"+"&bNamcu="+"<%=bNamcu%>"+"&bComm=okadd"+"&bReadwrite="+Noidung.CheckReadwrite.checked+"&bTTDuyet=false"
			<%else%>
			window.Noidung.action="frmVTDen.asp?bSoghinhancu="+"<%=bSoghinhancu%>"+"&bNamcu="+"<%=bNamcu%>"+"&bComm=okadd"+"&bReadwrite="+Noidung.CheckReadwrite.checked+"&bTTDuyet=false"
			<%end if%>			
			window.Noidung.submit()
		<%end if%>		
	}
}
function CmdNotOKDuyet_onclick() {
	<%if bComm="add" then %>
		alert("Bạn cần phải ghi nhận vănt thư trước");
		return false;
	<%end if%>
	if (KTNhap()){
		if(Noidung.TxtNgaynhan.value!=""){
			if (!isDate(Noidung.TxtNgaynhan.value)){
				alert("Ngày nhận không hợp lệ");
				Noidung.TxtNgaynhan.focus();
				return false;
			}
		}
		if(Noidung.TxtNgayky.value!=""){	
			if (!isDate(Noidung.TxtNgayky.value)){
				alert("Ngày ký không hợp lệ");
				Noidung.TxtNgayky.focus();
				return false;
			}
		}
		<%if bComm="edit" then%>
			window.Noidung.target="right"
			window.Noidung.action="frmVTDen.asp?bSoghinhancu="+"<%=bSoghinhancu%>"+"&bComm=okedit&bIDcu="+"<%=bIDcu%>"+"&bNamcu="+"<%=bNamcu%>"+"&bSogoccu="+"<%=bSogoccu%>"+"&bReadwrite="+Noidung.CheckReadwrite.checked+"&bTTDuyet=false"
			window.Noidung.submit()
		<%end if%>
	}
}
function CmdOKDuyet_onclick() {
		<%if bComm="add" then %>
			alert("Bạn cần phải cập nhật văn thư trước");
			return false;
		<%end if%>
	if (KTNhap()){
		if(Noidung.TxtNgaynhan.value!=""){
			if (!isDate(Noidung.TxtNgaynhan.value)){
				alert("Ngày nhận không hợp lệ");
				Noidung.TxtNgaynhan.focus();
				return false;
			}
		}
		if(Noidung.TxtNgayky.value!=""){	
			if (!isDate(Noidung.TxtNgayky.value)){
				alert("Ngày ký không hợp lệ");
				Noidung.TxtNgayky.focus();
				return false;
			}
		}
		<%if bComm="edit" then%>
			window.Noidung.target="right"
			window.Noidung.action="frmVTDen.asp?bSoghinhancu="+"<%=bSoghinhancu%>"+"&bComm=okedit&bIDcu="+"<%=bIDcu%>"+"&bNamcu="+"<%=bNamcu%>"+"&bSogoccu="+"<%=bSogoccu%>"+"&bReadwrite="+Noidung.CheckReadwrite.checked+"&bTTDuyet=true"
			window.Noidung.submit()
		<%end if%>
	}
}
function CmdAdd_onclick() {
	window.navigate("frmvtden.asp?bComm=add");
}
function CmdDuyet_onclick() {	
	<%if bComm="add" then %>
		alert("Bạn cần phải nhập văn thư trước");
		return false;
	<%end if%>
	if (!Noidung.CheckReadwrite.Checked){
	<%if bReadwrite then %>
		alert("Bạn cần phải nhập văn thư trước");
		return false;
	<%end if%>
	}
	mavt=window.Noidung.TxtID.value;
	window.Noidung.target="right";
	bduyet="duyetcanbo.asp?bstepduyet=0&bCommDuyetCB="+"<%=bComm%>"+"&MaVT="+mavt+"&bMaLoaiVT=1";
	window.Noidung.action=bduyet
	window.Noidung.submit();
}
function CmdXemNoidung_onclick() {
	<%if bComm="add" then %>
		alert("Bạn cần phải nhập văn thư trước");
		return false;
	<%end if%>
	if (Noidung.TxtID.value!=""){
		window.Noidung.target="_blank";
		bMa=Noidung.TxtID.value;
		window.Noidung.action="xemnoidung.asp?LoaiVt=1&bMa="+bMa+"&bNam="+"<%=bNam%>"
		window.Noidung.submit();
	}
}
function CmdNoidungtep_onclick() {
	<%if bComm="add" then %>
		alert("Bạn cần phải nhập văn thư trước");
		return false;
	<%end if%>
	<%if bQuyen="" or bQuyen="R" then%>
		alert("Bạn không có quyền sửa nội dung văn thư");
		return false;
	<%end if%>

	<% if bComm="edit" then%>
		bMa=Noidung.TxtID.value;
		a="../editor/frmedit.asp?bMa="+bMa+"&bLoaiVT=1&bNam="+"<%=bNam%>"+"&bNamcu="+"<%=bNamCu%>";
		window.Noidung.action=a;
		window.Noidung.target="right";
		window.Noidung.submit();
	<%end if%>
}
function CheckReadwrite_onclick(){
	if (Noidung.CheckReadwrite.checked){
		Noidung.CmdDuyet.disabled=true;
		CmdOK_onclick();
	}		
	else{
		Noidung.CmdDuyet.disabled=false;
		CmdOK_onclick();
	}
}
function CmdThemVV_onclick() {
	<%if bComm="add" then %>
		alert("Bạn cần phải nhập văn thư trước");
		return false;
	<%end if%>
	<%if bVuviec then%>
		window.Noidung.target="right"
		window.Noidung.action="frmvuviec.asp?bcallfrmvtden=ok&bTrichyeuvtden="+Noidung.TxtTrichyeu.value;
		window.Noidung.submit();
	<%else%>
		alert("B&#7841;n c&#7847;n ph&#7843;i ch&#7885;n m&#7897;t v&#259;n th&#432; l&#224;m vi&#7879;c");
	<%end if%>}

function CmdNext_onclick() {
	if(Noidung.TxtTTNoidung.value<Noidung.TxtSLNoidung.value){
		Noidung.TxtTTNoidung.value=++Noidung.TxtTTNoidung.value;		
	}
}

function CmdPrv_onclick() {
	if(Noidung.TxtTTNoidung.value>1){
		Noidung.TxtTTNoidung.value=--Noidung.TxtTTNoidung.value;
	}
}
function CmdNext1_onclick() {
	if(Noidung.TxtSLNoidung.value<3){
		Noidung.TxtSLNoidung.value=++Noidung.TxtSLNoidung.value;		
	}
}
function CmdPrv1_onclick() {
	if(Noidung.TxtSLNoidung.value>1){
		Noidung.TxtSLNoidung.value=--Noidung.TxtSLNoidung.value;
		if(Noidung.TxtTTNoidung.value>Noidung.TxtSLNoidung.value){
			Noidung.TxtTTNoidung.value=Noidung.TxtSLNoidung.value;
		}
	}
}
function ComboNguoiky_onchange() {
	Noidung.TxtNguoiky.value=Noidung.ComboNguoiky.value;
}
function ComboNguoinhan_onchange() {
	Noidung.TxtNguoinhan.value=Noidung.ComboNguoinhan.value;
}
function openW(sObj) {  
  popupWin = window.open('Search.asp?bType=DEN','new_page','width=300,height=300').focus();  
}
function openaddW(sObj) {
  popupWin = window.open('AddDV.asp?bType=DEN','new_page','width=300,height=300').focus();
}
function CmdEmail_onclick() {
	Noidung.target="_blank";
	bMa=Noidung.TxtID.value;
	Noidung.action="compose.asp?bLoaiVt=1&bMa="+bMa+"&bNam="+"<%=bNam%>";
	Noidung.submit();
}

//bg thphucluongmau
function Cmdworkflow_onclick() {
	if (Noidung.TxtSogoc.value==""){
		alert("B&#7841;n h&#227;y ch&#7885;n v&#259;n th&#432; c&#7847;n x&#7917; l&#253;");
		return false;
	}
	txtid=Noidung.TxtID.value;
	remote = window.open('frmselectcreateworkflow.asp?bComm=vtden&TxtID='+txtid,'pageLuongMau','width=320,height=175,top=180,left=250').focus();
}
//ed thphucluongmau
/*
function Cmdworkflow_onclick() {
	if (Noidung.TxtSogoc.value==""){
		alert("B&#7841;n h&#227;y ch&#7885;n v&#259;n th&#432; c&#7847;n x&#7917; l&#253;");
		return false;
	}
	if(!confirm("Bạn có muốn tạo luồng xử lý không ?")){
	  return false;
	}
	window.Noidung.target="right";
	window.Noidung.action="../workflow/createworkflow.asp?bComm=vtden";
	window.Noidung.submit();
}
*/
function TxtNgayky_onkeyup(str){
var keycode
keycode=window.event.keyCode
if (isEdit(keycode,str)){
	Noidung.TxtNgayky.value=editdate(trim(str))
}
}

function TxtNgaynhan_onkeyup(str){
var keycode
keycode=window.event.keyCode
if (isEdit(keycode,str)){
	Noidung.TxtNgaynhan.value=editdate(trim(str))
}
}
function TxtSogoc_onkeyup(){
var keycode
keycode=window.event.keyCode
if (keycode==13){
	Noidung.TxtTrichyeu.focus();
}
}

//-->
</SCRIPT>
<script language=VBScript runat=server>
	Function KTSoghinhan(bValueO,bValueY,loai)
		KTSoghinhan=false
		if loai="okedit" then			
				sSQL="Select * from Vtden where soghinhan= '"& Modistring(bValueO) &"' and year(ngaynhan)="& bValueY
				set RecKT=server.CreateObject("ADODB.Recordset")
				RecKT.CursorType=3
				RecKT.CacheSize=5
				RecKT.Open sSQL,Conn
				if (not RecKT.BOF) and (not RecKT.EOF) then
					KTSoghinhan=true
				end if
				RecKT.Close
				set RecKT=nothing				
		end if
		if loai="okadd" then
			sSQL="Select ID from vtden where soghinhan= '"& Modistring(bValueO) &"' and year(ngaynhan)="& bValueY
			set RecKT=server.CreateObject("ADODB.Recordset")
			RecKT.CursorType=3
			RecKT.CacheSize=5
			RecKT.Open sSQL,Conn
			if (not RecKT.BOF) and (not RecKT.EOF) then
				KTSoghinhan=true
			end if
			RecKT.Close
			set RecKT=nothing				
		end if			
	end function
	' H&#224;m &#273;&#7883;nh d&#7841;ng l&#7841;i ng&#224;y M/D/Y-> D/M/Y		
	Function FormatDate(vDate)
	   If Not IsNull(vDate) Then
	        vM = Right("0" & Month(vDate), 2)
	        vD = Right("0" & Day(vDate), 2)
	        vY = Right("19" & Year(vDate), 4)
	        FormatDate = vD & "/" & vM & "/" & vY
	   End If
	End Function
	Function SaveDate(vDate)
		dim bvitri1
		dim bvitri2
	   vDate=trim(cstr(vDate))
	   bvitri1=instr(1,vDate,"/")
	   bMonth=left(vDate,bvitri1-1)
	   bvitri2=instr(bvitri1+1,vDate,"/")
	   Dim Temp
	   Temp=right(vDate,len(vDate)-bvitri1)
	   bDay=left(Temp,bvitri2-bvitri1-1)
	   bYear=right(vDate,len(vDate)-bvitri2)
       SaveDate=bDay+"/"+bMonth+"/"+bYear
	End Function

	Function ModiString(mess_s)
		message = Replace("" & mess_s,"'", "''")
		ModiString=message
	End function
'Chuyen doi ma
Function DoiMa(st)
    Dim i
    st = Trim(st)
    If Len(st) = 0 Then
        DoiMa = ""
    Else
        For i = 1 To Len(st)
            Select Case Mid(st, i, 1)
                Case "-"
                    st=Replace(st,"-","_")
                Case "+"
                    st=Replace(st,"+","_")
                Case "*"
                    st=Replace(st,"*","_")
                Case "\"            
                    st=Replace(st,"\","_")
                Case "/"
                    st=Replace(st,"/","_")
                Case "?"
                    st=Replace(st,"?","_")
                Case "!"
                    st=Replace(st,"!","_")
                Case ","
                    st=Replace(st,",","_")
                Case ":"
                    st=Replace(st,":","_")
                Case ";"
                    st=Replace(st,";","_")
                Case "^"
                    st=Replace(st,"^","_")
                Case "|"
                    st=Replace(st,"|","_")
                Case " "
                    st=Replace(st," ","_")
                Case "("
                    st=Replace(st,"(","_")
                Case ")"
                    st=Replace(st,")","_")
                Case "["
                    st=Replace(st,"[","_")
                Case "]"
                    st=Replace(st,"]","_")
                Case "{"
                    st=Replace(st,"{","_")
                Case "}"
                    st=Replace(st,"}","_")
                Case "<"
                    st=Replace(st,"<","_")
                Case ">"
                    st=Replace(st,">","_")
                Case "."
                    st=Replace(st,".","_")
            End Select
        Next
        DoiMa = st
    End If
End Function	
</script>	
<body bgcolor=#F8F9D9 topmargin="0" leftmargin="0" style="font-family:Times New Roman">
<%if Msg<>"" then%>
	<p align=center><font face=Arial color=red><%=Msg%></font></p>
<%end if%>
<Form name="Noidung" Method="Post" >
<Textarea name=TxtBody style='visibility:hidden;position:absolute;top:0px;left:0px' rows="1" cols="20"><%=Request("TxtBody")%></textarea >
<%if bDisplay then
	txt="<input type=hidden name='TxtID' size='50' value='"& bID &"' >"
	Response.Write(txt)
else
	if bComm<>"add" then
		txt="<input type=hidden name='TxtID' value='"& bID &"' >"
		Response.Write(txt)
	else
		txt="<input type=hidden name='TxtID' value='"& AutoSoghinhan &"'size='50'></td>"
		Response.Write(txt)
	end if
end if%>
<!-- Form nhap lieu -->
<table width="100%" border="0" cellspacing="0" style="font-size:12pt; BORDER-BOTTOM-STYLE: none; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: solid;border-collapse:collapse; border-left-color:#C0C0C0; border-right-color:#C0C0C0; border-top-color:#C0C0C0; border-bottom-color:#C0C0C0" bordercolor="#111111" bgcolor="#BDD5D0">
  <tr>
    <td width="100%" colspan="6" align="center" bgcolor="#000080" >
    <font face="Arial" size=2 color="#FFFFFF">CÔNG VĂN ĐẾN</font></td>
  </tr>
<tr>
    <td width="15%" >Ngày đến</td>
    <td width="85%" colspan="5">
	<%if bDisplay then%>
			<input type=text name=TxtNgaynhan value="<%= FormatDate(bNgaynhan) %>" maxLength=10 size=10  style="font-family: Arial" LANGUAGE=javascript onkeyup="return TxtNgaynhan_onkeyup(this.value)">Số đến<input type=text name=TxtSoghinhan value='<%= bSoghinhan %>'  maxLength=20 size=10 style='font-family: Arial'>Số, ký hiệu<input type=text name=TxtSogoc value='<%= bSogoc %>' size=27 maxLength=27 style='font-family: Arial' LANGUAGE=javascript onkeyup="return TxtSogoc_onkeyup()">
	<%else
			if bComm<>"add"  then%>
				<input type=text name=TxtNgaynhan value="<%= FormatDate(bNgaynhan) %>" maxLength=10 size=10 style="font-family: Arial" LANGUAGE=javascript onkeyup="return TxtNgaynhan_onkeyup(this.value)">Số đến<input type=text name=TxtSoghinhan  value='<%= bSoghinhan %>' maxLength=20 size=10 style='font-family: Arial'>Số, ký hiệu<input type=text name=TxtSogoc value='<%= bSogoc %>' size=27 maxLength=27 style='font-family: Arial' LANGUAGE=javascript onkeyup="return TxtSogoc_onkeyup()">
			<%else%>
				<input type=text name=TxtNgaynhan value="<%= FormatDate(Date) %>" maxLength=10 size=10 style="font-family: Arial" LANGUAGE=javascript onkeyup="return TxtNgaynhan_onkeyup(this.value)">Số đến
				<%				
				Set RecMax=Server.createObject("ADODB.Recordset")
				RecMax.CursorType=3
				RecMax.CacheSize=5
				sSQL="Select soghinhan from vtden where year(ngaynhan)=year(getdate()) order by len(soghinhan),soghinhan"
				RecMax.Open sSQL,Conn
				if RecMax.recordcount then
					RecMax.movelast
					AutoSoghinhan =cstr(cint(RecMax("soghinhan"))+1)
				else
					AutoSoghinhan ="1"
				end if
				RecMax.close
				set RecMax=nothing
				%>
				<input type=text name=TxtSoghinhan value='<%= AutoSoghinhan %>' maxLength=20 size=10 style='font-family: Arial'> Số, ký hiệu <input type=text name=TxtSogoc size=27 maxLength=27 style='font-family: Arial' LANGUAGE=javascript onkeyup="return TxtSogoc_onkeyup()">
			<%end if%>
	<%end if %>	
	</td>			
  </tr>
  <tr>
    <td width="15%" >Trích yếu</td>
    <%	if bDisplay then%>
			<td width="85%" colspan="5">
            <textarea name=TxtTrichyeu maxLength=255 style='font-family: Arial; width:100%' rows=1 cols="20"><%= bTrichyeu %></textarea></td>
	<%else			
			if bComm<>"add" then%>
				<td width="85%" colspan="5">
                <textarea name=TxtTrichyeu maxLength=255 style='font-family: Arial; width:100%' rows=1 cols="20"><%= bTrichyeu %></textarea></td>
			<%else%>
				<%if request("MsgNo") then %>
					<td width="85%" colspan="5">
                    <textarea name=TxtTrichyeu  maxLength=255 style='font-family: Arial; width:100%' rows=1 cols="20"><%=Request("TxtSubject")%></textarea></td>
				<%else%>
					<td width="85%" colspan="5">
                    <textarea name=TxtTrichyeu maxLength=255 style='font-family: Arial; width:100%' rows=1 cols="20"></textarea></td>
				<%end if%>
			<%end if%>
	<%end if%>    
  </tr>
  </tr>
  <tr>
    <td width="15%" >Tóm tắt ND</td>
    <%	if bDisplay then%>
			<td width="85%" colspan="5">
            <textarea name=TxtTomtat style="font-family:Arial; width:100%" rows=2 cols="20"><%=bTomtat%></textarea></td>
	<%else			
			if bComm<>"add" then%>
				<td width="85%" colspan="5">
                <textarea name=TxtTomtat style="font-family:Arial; width:100%" rows=2 cols="20"><%=bTomtat%></textarea></td>
			<%else%>
				<td width="85%" colspan="5">
                <textarea name=TxtTomtat style="font-family:Arial; width:100% " rows=2 cols="20"></textarea></td>
			<%end if%>
	<%end if%>    
  </tr>
   <tr>
    <td width="15%" >Ngày CV</td>
	<td width="20%">
    <%	if bDisplay then%>
			<input type=text name=TxtNgayky value="<%= FormatDate(bNgayky) %>" maxLength=10 size=15 style="font-family: Arial; width:100%" LANGUAGE=javascript onkeyup="return TxtNgayky_onkeyup(this.value)"></td>
	<%else
			if bComm<>"add" then%>
				<input type=text name=TxtNgayky value="<%= FormatDate(bNgayky) %>" maxLength=10 size=15 style="font-family: Arial; width:100%" LANGUAGE=javascript onkeyup="return TxtNgayky_onkeyup(this.value)"></td>
			<%else%>
				<input type=text name=TxtNgayky maxLength=10 size=15 style="font-family: Arial; width:100%" LANGUAGE=javascript onkeyup="return TxtNgayky_onkeyup(this.value)"></td>
			<%end if%>
	<%end if%>           
    <td width="15%" align="center">Người ký</td>
	<td width="25%">
    <%if bDisplay then%>
			<input type=text name=TxtNguoiky Value='<%= bNguoiky %>' maxLength=60 style='font-family: Arial; width:100%' size="20"></td>
	<%else
			if bComm<>"add" then%>
				<input type=text name=TxtNguoiky Value='<%= bNguoiky %>' maxLength=60 style='font-family: Arial; width:100%'></td>
			<%else%>
				<input type=text name=TxtNguoiky maxLength=60 style='font-family: Arial; width:100%'></td>
			<%end if
	end if%>
<%
	sSQL="Select ten from doitac_nguoi Order by Ten"
	Set RecNK=Server.CreateObject("ADODB.Recordset")
	RecNK.CursorType=3
	RecNK.CacheSize=5
	RecNK.Open sSQL,Conn
%>
	<td width="25%"><Select size=1 name="ComboNguoiky" style="font-family: Arial; width:100%" language="Javascript" onchange="return ComboNguoiky_onchange()">
		<Option value='' selected>
		<% Do while not RecNK.EOF %>
		<Option value='<%=RecNK("Ten")%>'><%=RecNK("Ten")%>
		<% 
		RecNK.MoveNext
		Loop
		txt="</Select>"
		Response.write (txt)
		RecNK.close
		Set RecNK=nothing	%>
	</td>
  </tr>
  <tr>
   	<td width="15%"><input type=button name=CmdS value="CQ ban hành" onclick="javaScript:openW()" style="font-family:Times New Roman;width:100%; background-color:#BDD5D0"></td> 
	<td width="85%" colspan="5">
    <input type=text name=ComboDoitac maxLength=500 value='<%= bDoitac%>' style='font-family: Arial; width:100%' size="20"></TD>
  </tr>
  <tr>
	    <%if bDisplay then%>
				<td width="15%"><input type=button name=CmdAddDV value="Đơn vị xử lý" onclick="javaScript:openaddW()" style="font-family:Times New Roman; width:100%; background-color:#BDD5D0"></td>
				<td width="85%" colspan="5">
                <input type=text name=TxtNoinhan maxLength=500 value='<%= bNoinhan %>' style='font-family:Arial; width:100%' size="20"></td>
		<%else
				if bComm<>"add" then%>
					<td width="15%"><input type=button name=CmdAddDV value="Đơn vị xử lý" onclick="javaScript:openaddW()" style="font-family: Times New Roman; width:100%; background-color:#BDD5D0"></td>
					<td width="85%" colspan="5">
                    <input type=text name=TxtNoinhan maxLength=500 value='<%= bNoinhan %>' style='font-family: Arial; Width:100%' size="20"></td>
				<%else%>
					<td width="15%"><input type=button name=CmdAddDV value="Đơn vị xử lý" onclick="javaScript:openaddW()" style="font-family: Times New Roman; width:100%; background-color:#BDD5D0"></td>
					<td width="85%" colspan="5"><input type=text name=TxtNoinhan maxLength=500 style='font-family: Arial; Width:100%' size="20"></td>
				<%end if%>
		<%end if %>
  </tr>
  
  <tr>
    <td width="15%" >Khẩn/mật</td>
	<td width="35%" colspan="2">
		<select size="1" name="ComboTinhchat" style="font-family: Arial; height: 23; position: relative; width:100%">
    <%
			sSQL="Select * from Tinhchat order by ma"
			Set RecTC=Server.CreateObject("ADODB.Recordset")
			RecTC.CursorType=3
			RecTC.CacheSize=5
			RecTC.Open sSQL,Conn
			Do While not RecTC.EOF
				if bDisplay then
					if RecTC("ma")=bTinhchat then		
		%>				<option Selected value=<%=RecTC("Ma")%>><%=RecTC("Ten")%>
		<%			else%>
						<option value=<%=RecTC("Ma")%>><%=RecTC("Ten")%>
		<%			end if
				else%>
					<%if bComm<>"add" then
						if RecTC("ma")=bTinhchat then		
		%>					<option Selected value=<%=RecTC("Ma")%>><%=RecTC("Ten")%>
		<%				else%>
							<option value=<%=RecTC("Ma")%>><%=RecTC("Ten")%>
		<%				end if
					else%>
						<option value=<%=RecTC("Ma")%>><%=RecTC("Ten")%>
					<%end if%>
		<%		end if
				RecTC.MoveNext
			Loop
			RecTC.Close
			set RecTC=nothing
		%>    
      	</select>
	</td>
    <td width="50%" colspan="2" align="center"><label for=C1 accesskey="V">Điểm <u>v</u>ăn bản<br>
    (Thống kê văn bản quan trọng)</label>
   		<%if bBaocao then%>
				<input name=ChkBC type=checkbox  checked value="ON" id=C1>
		<%else%>
				<input name=ChkBC type=checkbox value="ON" id=C1>
		<%end if%>
	</td>
  </tr>

<tr>
    <td width="15%" >Tên loại VB</td>
    <td width="85%" colspan="4">
	<%
   		sSQL="Select * from PHAN_LOAI_VB order by MA_KY_HIEU"
		Set RecCB=server.CreateObject("ADODB.Recordset")
		RecCB.CursorType=3
		RecCB.CacheSize=5
		RecCB.Open sSQL,Conn%>
		<select size=1 name=ComboPhanloai style='font-family: Arial; width:100%'>
		<%Do While not RecCB.EOF				
				if bDisplay then
					if trim(cstr(RecCB("IDLOAI")))=trim(bPhanloai) then		
		%>				<option Selected value="<%=RecCB("IDLOAI")%>"><%=RecCB("TEN_HINH_THUC")%>
		<%		else%>
						<option value="<%=RecCB("IDLOAI")%>"><%=RecCB("TEN_HINH_THUC")%>
		<%		end if
				else%>
					<%if bComm<>"add" then
						if trim(cstr(RecCB("IDLOAI")))=trim(bPhanloai) then		
		%>					<option Selected value="<%=RecCB("IDLOAI")%>"><%=RecCB("TEN_HINH_THUC")%>
		<%			else%>
							<option value="<%=RecCB("IDLOAI")%>"><%=RecCB("TEN_HINH_THUC")%>
		<%			end if
					else%>
						<option value="<%=RecCB("IDLOAI")%>"><%=RecCB("TEN_HINH_THUC")%>
					<%end if%>
		<%		end if
				RecCB.MoveNext
		Loop
		txt="</select>"
		Response.Write(txt)
		RecCB.Close
		Set RecCB=nothing%>
	</select></td>	
	<!-- DIA CHI LUU TRU -->
<!--
    <td width="15%" align=center>Địa chỉ lưu trữ</td>
    <td width="50%" colspan="2">
      <p align="center">
      <%
   		sSQL="Select * from Diachiluutru"
		Set RecCB=server.CreateObject("ADODB.Recordset")
		RecCB.CursorType=3
		RecCB.CacheSize=5
		RecCB.Open sSQL,Conn
		Txt="<select size=1 name=TxtDiachiluutru style='font-family: Arial; height: 23; position: relative; width:100%'>"
		Response.Write(txt)%>				
		<%Do While not RecCB.EOF				
				if bDisplay then
					if trim(cstr(RecCB("IDLuutru")))=trim(bDiachiluutru) then		
	%>				<option Selected value=<%=RecCB("IDLuutru")%>><%=RecCB("Ten")%>
		<%			else%>
						<option value=<%=RecCB("IDLuutru")%>><%=RecCB("Ten")%>
		<%			end if
				else%>
					<%if bComm<>"add" then
						if trim(cstr(RecCB("IDLuutru")))=trim(bDiachiluutru) then		
%>					 <option Selected value=<%=RecCB("IDLuutru")%>><%=RecCB("Ten")%>
		<%			else%>
						<option value=<%=RecCB("IDLuutru")%>><%=RecCB("Ten")%>
		<%				end if
					else%>
						<option value=<%=RecCB("IDLuutru")%>><%=RecCB("Ten")%>
					<%end if%>
		<%		end if
				RecCB.MoveNext
		Loop
		txt="</select>"
		Response.Write(txt)
		RecCB.Close
		Set RecCB=nothing%>
	</td>		
	-->
  </tr>
  
  <tr>
    <td width="15%" >Từ khóa</td>
    <%if bDisplay then%>
		<td width="20%">
        <input type=text name=TxtTukhoa value='<%= bTukhoa %>' maxLength=100 style='font-family: Arial;width: 100%' size="20"></td>
		<% if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),5)="1" or Session("IsAdmin") then	%>
			<td width="15%" align=center><Button name="CmdOK" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="CmdEmail_onclick()" accesskey="E"><u>E</u>mail</Button></td>
		<% else %>
			<td width="15%" align=center><Button disabled name="CmdOK" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="CmdEmail_onclick()" accesskey="E"><u>E</u>mail</Button></td>
		<% end if %>

		<% if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),8)="1" or Session("IsAdmin") then %>
			<td width="25%" align=center><Button name="CmdOK" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="Cmdworkflow_onclick()" accesskey="A"><p>T<u>ạ</u>o luồng xử lý</p></Button></td>
		<%else%>
			<td width="25%" align=center><Button disabled name="CmdOK" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="Cmdworkflow_onclick()" accesskey="A"><p>T<u>ạ</u>o luồng xử lý</p></Button></td>
		<%end if%>
	<%else			
			if bComm<>"add" then%>
				<td width="20%">
                <input type=text value='<%= bTukhoa %>' name=TxtTukhoa maxLength=100 style='font-family: Arial;width: 100%' size="20"></td>
				<% if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),5)="1" or Session("IsAdmin") then	%>
					<td width="15%" align=center><Button name="CmdOK" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="CmdEmail_onclick()" accesskey="E"><u>E</u>mail</Button></td>
				<% else %>
					<td width="15%" align=center><Button disabled name="CmdOK" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="CmdEmail_onclick()" accesskey="E"><u>E</u>mail</Button></td>					
				<% end if %>
				<% if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),8)="1" or Session("IsAdmin") then %>
					<td width="25%"><Button name="CmdOK" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="Cmdworkflow_onclick()" accesskey="A"><p>T<u>ạ</u>o luồng xử lý</p></Button></td>
				<%else%>
					<td width="25%"><Button disabled name="CmdOK" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="Cmdworkflow_onclick()" accesskey="A"><p>T<u>ạ</u>o luồng xử lý</p></Button></td>
				<%end if%>				
			<%else%>
				<td width="20%">
                <input type=text name=TxtTukhoa maxLength=100 style='font-family: Arial;width: 100%' size="20"></td>
				<td width="15%" ><Button disabled name="CmdOK" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="CmdEmail_onclick()" accesskey="E"><u>E</u>mail</Button></td>
				<td width="25%"><Button disabled name="CmdOK" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="Cmdworkflow_onclick()" accesskey="A"><p>T<u>ạ</u>o luồng xử lý</p></Button></td>
			<%end if
	end if%>    
    <td width="25%"><Button name="CmdOK" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="return CmdOK_onclick()" accesskey="G"><p><u>G</u>hi nhận</p></Button></td>
  </tr>
</table>

<!--Quy dinh quyen, Noi dung van ban-->
<Table width="100%" border="0" cellspacing="1" style="font-size:12pt; BORDER-BOTTOM-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: solid;border-left-color:#C0C0C0; border-right-color:#C0C0C0; border-top-color:#C0C0C0; border-bottom-color:#C0C0C0"  bgcolor="#BDD5D0" cellpadding="1">
<tr bgcolor="#000080">
	<td width="50%" colspan="2" align="center" >
    <font color="#FFFFFF"><b>Quy định quyền văn bản</b></font></td>
	<td width="25%" align="center"><font color="#FFFFFF"><b>Nội dung văn bản</b></font></td>
	<td width="25%" align="center"><font color="#FFFFFF"><b>Chức năng</b></font></td>
</tr>
<tr>
	<td width="25%" align=center><label for=C2 accesskey="C"><u>C</u>ho phép công bố</label>
	<%	
					if bDisplay then
						if  bReadwrite then
							if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),9)="1" or Session("IsAdmin") then	%>
                                <input type=checkbox name=CheckReadwrite Checked language=javascript onclick='return CheckReadwrite_onclick()' value="ON" id=C2></td>
							<%else%>
                                <input type=checkbox name=CheckReadwrite Checked disabled=true  language=javascript onclick='return CheckReadwrite_onclick()' value="ON" id=C2></td>
							<%end if
						else
							if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),9)="1" or Session("IsAdmin") then	%>
                                <input type=checkbox name=CheckReadwrite language=javascript onclick='return CheckReadwrite_onclick()' value="ON" id=C2></td>
							<%else%>
                                <input type=checkbox name=CheckReadwrite disabled=true  language=javascript onclick='return CheckReadwrite_onclick()' value="ON" id=C2></td>
							<%end if
						end if
					else
						if bComm<>"add" then
							if  bReadwrite then							
								if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),9)="1" or Session("IsAdmin") then	%>
                                    <input type=checkbox name=CheckReadwrite Checked language=javascript onclick='return CheckReadwrite_onclick()' value="ON" id=C2></td>
								<%else%>
                                    <input type=checkbox name=CheckReadwrite Checked disabled=true  language=javascript onclick='return CheckReadwrite_onclick()' value="ON" id=C2></td>
								<%end if
							else
								if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),9)="1" or Session("IsAdmin") then %>
                                    <input type=checkbox name=CheckReadwrite language=javascript onclick='return CheckReadwrite_onclick()' value="ON" id=C2></td>
								<%else%>
                                    <input type=checkbox name=CheckReadwrite disabled=true  language=javascript onclick='return CheckReadwrite_onclick()' value="ON" id=C2></td>
								<%end if
							end if
						else
							if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),9)="1" or Session("IsAdmin") then	%>
                                <input type=checkbox name=CheckReadwrite language=javascript onclick='return CheckReadwrite_onclick()' value="ON" id=C2></td>
							<%else%>
                                <input type=checkbox name=CheckReadwrite disabled=true  language=javascript onclick='return CheckReadwrite_onclick()' value="ON" id=C2></td>
							<%end if			
						end if
					end if
				%>       
			<%  if bDisplay then
						if  bReadwrite then%>
							<td width="25%"><Button disabled name='CmdDuyet' style='font-family: Arial;width: 100%' LANGUAGE=javascript onclick='return CmdDuyet_onclick()'accesskey="Q"><p><u>Q</u>uy định quyền</p></Button></td>
						<%else
							if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),9)="1" or Session("IsAdmin") then	%>
								<td width="25%"><Button  name='CmdDuyet' style='font-family: Arial; width:100%' LANGUAGE=javascript onclick='return CmdDuyet_onclick()' accesskey="Q"><p><u>Q</u>uy định quyền</p></Button></td>
							<%else%>
								<td width="25%"><Button  disabled name='CmdDuyet' style='font-family: Arial; width: 100%' LANGUAGE=javascript onclick='return CmdDuyet_onclick()'accesskey="Q"><p><u>Q</u>uy định quyền</p></Button></td>
							<%end if
						end if
					else
						if bComm<>"add" then
							if  bReadwrite then%>
								<td width="25%"><Button  disabled name='CmdDuyet' style='font-family: Arial;width: 100%' LANGUAGE=javascript onclick='return CmdDuyet_onclick()'accesskey="Q"><p><u>Q</u>uy định quyền</p></Button></td>
							<%else
								if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),9)="1" or Session("IsAdmin") then%>
									<td width="25%"><Button  name='CmdDuyet' style='font-family: Arial;width: 100%' LANGUAGE=javascript onclick='return CmdDuyet_onclick()'accesskey="Q"><p><u>Q</u>uy định quyền</p></Button></td>
								<%else%>
									<td width="25%"><Button  disabled name='CmdDuyet' style='font-family: Arial;width: 100%' LANGUAGE=javascript onclick='return CmdDuyet_onclick()'accesskey="Q"><p><u>Q</u>uy định quyền</p></Button></td>
								<%end if
							end if
						else
							if bComm="add" then
								if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),9)="1" or Session("IsAdmin") then	%>
									<td width="25%"><Button  disabled name='CmdDuyet' style='font-family: Arial;width:100%' LANGUAGE=javascript onclick='return CmdDuyet_onclick()'accesskey="Q"><p><u>Q</u>uy định quyền</p></Button></td>
								<%else%>
									<td width="25%"><Button disabled name='CmdDuyet' style='font-family: Arial;width: 100%' LANGUAGE=javascript onclick='return CmdDuyet_onclick()'accesskey="Q"><p><u>Q</u>uy định quyền</p></Button></td>
								<%end if
							else
								if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),9)="1" or Session("IsAdmin") then	%>
									<td width="25%"><Button name='CmdDuyet' style='font-family: Arial;width: 100%' LANGUAGE=javascript onclick='return CmdDuyet_onclick()'accesskey="Q"><p><u>Q</u>uy định quyền</p></Button></td>
								<%else%>
									<td width="25%"><Button disabled name='CmdDuyet' style='font-family: Arial;width: 100%' LANGUAGE=javascript onclick='return CmdDuyet_onclick()'accesskey="Q"><p><u>Q</u>uy định quyền</p></Button></td>
								<%end if
							end if
						end if
					end if%>
	<%if bComm="add" then%>
		<td width="25%" align=center><Button disabled name="CmdXemNoidung" style="font-family: Arial;width: 100%" LANGUAGE=javascript onclick="return CmdXemNoidung_onclick()" accesskey="X"><p><u>X</u>em nội dung văn thư</p></Button></td>
	<%else%>
		<td width="25%" align=center><Button name="CmdXemNoidung" style="font-family: Arial;width: 100%" LANGUAGE=javascript onclick="return CmdXemNoidung_onclick()" accesskey="X"><p><u>X</u>em nội dung văn thư</p></Button></td>
	<%end if%>
	<td width="25%" align=center><Button name="CmdAdd" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="return CmdAdd_onclick()" accesskey="T"><p><u>T</u>hêm mới</p></Button></td>
</tr>
<tr>
	<% if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),9)="1" or Session("IsAdmin") then	%>
		<%if bComm="add" then%>
			<%if bTTDuyet then%>
				<td width="25%"><Button disabled name="CmdOKDuyet" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="return CmdOKDuyet_onclick()" accesskey="D"><p><u>D</u>uyệt nội dung</p></Button></td>
			<%else%>
				<td width="25%" ><Button disabled name="CmdOKDuyet" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="return CmdOKDuyet_onclick()" accesskey="D"><p><u>D</u>uyệt nội dung</p></Button></td>
			<%end if%>
		<%else%>
			<%if bTTDuyet then%>
				<td width="25%"><Button disabled name="CmdOKDuyet" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="return CmdOKDuyet_onclick()" accesskey="Đ"><p><u>D</u>uyệt nội dung</p></Button></td>
			<%else%>
				<td width="25%" ><Button name="CmdOKDuyet" style="font-family: Arial;width:100%"  LANGUAGE=javascript onclick="return CmdOKDuyet_onclick()" accesskey="D"><p><u>D</u>uyệt nội dung</p></Button></td>
			<%end if%>
		<%end if%>
	<%else%>					
		<td width="25%"><Button disabled name="CmdOKDuyet" style="font-family: Arial; width:100%"  LANGUAGE=javascript onclick="return CmdOKDuyet_onclick()" accesskey="D"><p><u>D</u>uyệt nội dung</p></Button></td>
	<%end if%>
	<% if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),9)="1" or Session("IsAdmin") then	%>
			<%if bTTDuyet then%>
				<td width="25%"><Button name="CmdNotOKDuyet" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="return CmdNotOKDuyet_onclick()" accesskey="H"><p><u>H</u>ủy duyệt nội dung</p></Button></td>
			<%else%>
				<td width="25%"><Button disabled=true name="CmdNotOKDuyet" style="font-family: Arial;width: 100%"  LANGUAGE=javascript onclick="return CmdNotOKDuyet_onclick()" accesskey="H"><p><u>H</u>ủy duyệt nội dung</p></Button></td>
			<%end if%>
	<%else%>
		<td width="25%"><Button disabled=true name="CmdNotOKDuyet" style="font-family: Arial;width:100%"  LANGUAGE=javascript onclick="return CmdNotOKDuyet_onclick()" accesskey="H"><p><u>H</u>ủy duyệt nội dung</p></Button></td>
	<%end if%>		
	<%if bComm="add" then%>
		<%if bTTDuyet then%>
			<td width="25%"><Button disabled name="CmdNoidungtep" style="font-family: Arial;  height: 25; position: relative; width: 100%" LANGUAGE=javascript onclick="return CmdNoidungtep_onclick()" accesskey="S"><p><u>S</u>oạn nội dung văn thư</p></Button></td>
		<%else%>
			<td width="25%"><Button disabled name="CmdNoidungtep" style=" font-family: Arial; height: 25; position: relative; width:100%" LANGUAGE=javascript onclick="return CmdNoidungtep_onclick()" accesskey="S"><p><u>S</u>oạn nội dung văn thư</p></Button></td>
		<%end if%>
	<%else%>
		<%if bTTDuyet then%>
			<td width="25%"><Button disabled name="CmdNoidungtep" style="font-family: Arial;  height: 25; position: relative; width: 100%" LANGUAGE=javascript onclick="return CmdNoidungtep_onclick()" accesskey="S"><p><u>S</u>oạn nội dung văn thư</p></Button></td>
		<%else%>
			<td width="25%"><Button name="CmdNoidungtep" style="  font-family: Arial;height: 25; position: relative; width:100%" LANGUAGE=javascript onclick="return CmdNoidungtep_onclick()" accesskey="S"><p><u>S</u>oạn nội dung văn thư</p></Button></td>
		<%end if%>
	<%end if%>
	<td width="25%"><Button name="CmdExit" style="font-family: Arial; width:100%"   LANGUAGE=javascript onclick="return CmdExit_onclick()" accesskey="y"><p>Qua<u>y</u> lại</p></Button></td>
</tr>
</Table>
</form>
</body>
<%
	Conn.Close
	set Conn=nothing
%></html>